import logging
from redis import StrictRedis


class Config(object):
    """项目配置"""
    DEBUG = True
    """设置session的时候用到的"""
    SECRET_KEY = "FSJDFLSKDFJLKSDJFKLSDJFK"

    """为数据库添加配置"""
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # TODO 默认提交之后处理
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    """redis配置"""
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    """配置保存session"""
    SESSION_TYPE = "redis"
    """开启session签名"""
    SESSION_USE_SIGNER = True
    """制定SEEION保存在redis中"""
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    """设置session需要过期，flask中默认不是过期的"""
    SESSION_PERMANENT = False
    """设置过期时间  ,三天"""
    PERMANENT_SESSION_LIFETIME = 86400 * 3

    """设置日志等级"""
    LOG_LEVEL = logging.DEBUG


"""设置几个开发环境，当 处于不同的开发阶段的时候，选用不同的调试阶段"""
class DevelopmentConfig(Config):
    """开发环境下的配置"""
    DEBUG = True


class ProductionConfig(Config):
    """生产环境下的配置"""
    DEBUG = False


class TestingConfig(Config):
    """单元测试环境下的配置"""
    DEBUG = True
    TESTING = True


config = {
    "development": DevelopmentConfig,
    "production": ProductionConfig,
    "testing": TestingConfig
}